Page({
  data: {
    departure: '',
    destination: '',
    date: '选择出发日期',
    minDate: '',
    maxDate: ''
  },

  onLoad() {
    this.setData({
      minDate: this.formatDate(new Date()), // 今天的日期
      maxDate: this.formatDate(this.calculateMaxDate(14)) // 15天后的日期
    });
  },

  calculateMaxDate(days) {
    const date = new Date();
    date.setDate(date.getDate() + days);
    return date;
  },

  formatDate(date) {
    const year = date.getFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2);
    const day = ('0' + date.getDate()).slice(-2);
    return `${year}-${month}-${day}`;
  },

  onDepartureInput(e) {
    this.setData({
      departure: e.detail.value
    });
  },

  onDestinationInput(e) {
    this.setData({
      destination: e.detail.value
    });
  },

  onDateChange(e) {
    this.setData({
      date: e.detail.value
    });
  },

  onSearch() {
    const { departure, destination, date } = this.data;
     // 把按钮的loading状态显示出来

     this.setData({

      loading: true

    })
    if (!departure || !destination || !date) {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      });
      return;
    }
    
    // 发起请求或处理查询逻辑
    wx.showToast({
      title: '查询功能待实现',
      icon: 'none'
    });
  }
});
